@echo off
setlocal enabledelayedexpansion

:: 获取日期（格式：YYYY-MM-DD）
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (
    set "year=%%a"
    set "month=%%b"
    set "day=%%c"
)
:: 确保月份和日期为两位数
if "!month:~1!"=="" set "month=0!month!"
if "!day:~1!"=="" set "day=0!day!"
set "date=!year!-!month!-!day!"

:: 获取时间（格式：HH:MM:SS）
for /f "tokens=1-3 delims=:. " %%a in ('time /t') do (
    set "hour=%%a"
    set "minute=%%b"
)
:: 补充当前秒数（time /t不返回秒，这里通过额外命令获取）
for /f "tokens=3 delims=:. " %%s in ('echo %time%') do set "second=%%s"
:: 确保小时、分钟、秒为两位数
if "!hour:~1!"=="" set "hour=0!hour!"
if "!minute:~1!"=="" set "minute=0!minute!"
if "!second:~1!"=="" set "second=0!second!"
set "time=!hour!:!minute!:!second!"

:: 组合日期时间并生成头文件
set "buildtime=!date! !time!"
echo #ifndef BUILDTIME_H > ..\inc\buildtime.h
echo #define BUILDTIME_H >> ..\inc\buildtime.h
echo. >> buildtime.h
echo #define BUILDTIME "%buildtime%" >> ..\inc\buildtime.h
echo. >> ..\inc\buildtime.h
echo #endif // BUILDTIME_H >> ..\inc\buildtime.h

endlocal